#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   logDialog.py
@Time    :   2020/04/08 10:42:14
@Author  :   Xiong qiufeng
@Version :   1.0
@Contact :   1528399071@qq.com
@License :   (C)Copyright 2017-2018, Liugroup-NLPR-CASIA
@Desc    :   None
'''


from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

import os
from conf import conf 

from ui.logDialog import Ui_Dialog
class logDialog(QDialog, Ui_Dialog):

    log_path = conf.LOG_PATH
    def __init__(self, parent=None):
        super(logDialog, self).__init__(parent)
        self.setupUi(self)
        self.setWindowTitle('操作日志')

        # 字体
        # self.font = QFont()
        # self.font.setFamily("Agency FB")
        # self.font.setPointSize(28)

        # 字体
        if conf.SYSTEM == "windows":
            self.setMinimumWidth(1500)
            self.setMinimumHeight(800)
        # qr = self.frameGeometry()

        # 实例化列表模型，添加数据
        self.listViewModel = QStringListModel()
        # 文件列表
        self.fileList=[]
        # 设置列表视图的模型
        self.listView.setModel(self.listViewModel)
        # 单击触发自定义的槽函数
        self.listView.clicked.connect(self.listViewClicked)

        self.listView.setMaximumWidth(200)

    def readLog(self):
        self.fileList = os.listdir(self.log_path)
        self.fileList.sort()
        self.listViewModel = None
        self.listViewModel = QStringListModel()
        self.listViewModel.setStringList(self.fileList)
        self.listView.setModel(self.listViewModel)

    def showEvent(self, e):
        self.readLog()

    def listViewClicked(self, qModelIndex):
        file = self.fileList[qModelIndex.row()]
        self.textBrowser.clear()
        with open("%s/%s"%(self.log_path,file), 'r') as r:
            for line in r.readlines():
                self.textBrowser.append(str(line))
        